/*
* @Author: steven.wang
* @Date:   2019-05-13 14:56:29
* @Last Modified by:   steven.wang
* @Last Modified time: 2019-05-15 10:37:57
*/
// const moment = require('moment');
const multer = require ('multer');
// const path = require('path');
// const fs = require('fs');
const express = require('express');
const router = express.Router();
const baseController = require('../controllers/base');
const upload = multer({
	storage: multer.diskStorage({
	    // destination: function (req, file, cb) {
	    // 	let now = moment();
	    //     let uploadPath = path.join(__dirname, '../upload');
	    // 	let fileYear = path.join(__dirname, '../upload/' + now.format('YYYY'));
	    // 	let fileMonth = path.join(__dirname, '../upload/' + now.format('YYYY') + '/' + now.format('MM'));
	    // 	let fileDay = path.join(__dirname, '../upload/' + now.format('YYYY') + '/' + now.format('MM') + '/' + now.format('DD'));
	    //     if(!fs.existsSync(uploadPath)){
	    //         fs.mkdirSync(uploadPath);
	    //     }
	    // 	if(!fs.existsSync(fileYear)){
	    //         fs.mkdirSync(fileYear);
	    //     }
	    // 	if(!fs.existsSync(fileMonth)){
	    //         fs.mkdirSync(fileMonth);
	    //     }
	    // 	if(!fs.existsSync(fileDay)){
	    //         fs.mkdirSync(fileDay);
	    //     }
	    //     cb(null, fileDay);
	    // },
	    filename: function (req, file, cb) {
	        // 将保存文件名设置为 字段名 + 时间戳，比如 logo-1478521468943
	        cb(null, file.originalname);
	    }
	})
}).single('file');

// 获取图片列表
router.post('/upload', upload, baseController.upload);

module.exports = router;
